package com.fs.util;

import com.fs.entity.Administrators;
import com.fs.entity.Students;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

public class AdminContext {  private static final  String LOGIN_ADMIN = "current_admin";

    //Spring提供了获取javaWeb核心对象的工具类:  RequestContextHolder

    public static HttpSession getSession(){
        return  ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }
    /**
     * 把user保存到Session域
     */
    public static void setAdmin(Administrators admin){
        getSession().setAttribute(LOGIN_ADMIN,admin);
    }

    public static Administrators getAdmin(){
        return (Administrators) getSession().getAttribute(LOGIN_ADMIN);
    }
}
